<template>
    <div>
        <h3>新增页面</h3>

        <table class="table">
            <tbody>
                <tr>
                    <td>优惠券名称</td>
                    <td>
                        <input type="text" v-model="data.Ename">
                    </td>
                </tr>
                <tr>
                    <td>结束时间</td>
                    <td>
                        <input type="date" v-model="data.Edate">
                    </td>
                </tr>
                <tr>
                    <td>优惠券颜色</td>
                    <td>
                        <input type="text" v-model="data.Ecolour">
                    </td>
                </tr>
                <tr>
                    <td>优惠券描述</td>
                    <td>
                        <input type="text" v-model="data.Emiao">
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <input type="button" value="新增" @click="add">
                        
                    </td>
                </tr>
            </tbody>
        </table>

    </div>
</template>

<script setup lang="ts">

import {ref} from 'vue'
import {useRouter} from 'vue-router'
import axios from 'axios'

const router=useRouter()

const data=ref({
  "Eid": 0,
  "Ename": "",
  "Edate": "",
  "Ecolour": "",
  "Emiao": ""
})

const add=()=>{
    axios.post("https://localhost:7087/api/Emp/Add",data.value).then(res=>{
        if(res.data==-1)
        {
            alert("相同的折扣券名称只能出现一次");
            return;
        }
        if(res.data>0)
        {
            alert("新增成功");
            router.push({path:"/"})
        }
        else
        {
            alert("新增失败");
        }
    })
}

</script>

<style scoped>

</style>